import { createRealTimeMonitoring, getMaxId } from './statements';
import { getDB } from '../../db';

/**
 * 添加视频实时监控标注
 * @param markInfoInfos 视频标注信息
 */
export const addRealTimeMarkInfo = (markInfoInfos: LX.DBService.MarkRealTimeInfoInfo[]) => {
  const insertStatement = createRealTimeMonitoring();
  const db = getDB();
  const getMaxIdStatment = getMaxId();
  let rest = getMaxIdStatment.get();
  let maxId = '0';
  if (rest?.id !== null) {
    maxId = rest ? rest.id : '0';
  }
  db.transaction((markInfoInfos: LX.DBService.MarkRealTimeInfoInfo[]) => {
    for (const markInfoInfo of markInfoInfos) {
      maxId = (parseInt(maxId) + 1).toString();
      insertStatement.run({
        id: maxId,
        startTime: markInfoInfo.startTime,
        endTime: markInfoInfo.endTime,
        label: markInfoInfo.label,
        describe: markInfoInfo.describe,
        channel: markInfoInfo.channel,
        status: markInfoInfo.status,
        createTime: markInfoInfo.createTime,
        createUser: markInfoInfo.createUser,
      });
    }
  })(markInfoInfos);
};
